$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'capital/merchantorderaccount/list',
        datatype: "json",
        colModel: [			
			{ label: 'orderAccountId', name: 'orderAccountId', index: 'order_account_id', width: 50, key: true },
			{ label: '分配订单id', name: 'orderAllotId', index: 'order_allot_id', width: 80 }, 			
			{ label: '订单id', name: 'orderId', index: 'order_id', width: 80 }, 			
			{ label: '会员用户名', name: 'memberId', index: 'member_id', width: 80 }, 			
			{ label: '供应商id', name: 'supplierId', index: 'supplier_id', width: 80 }, 			
			{ label: '工厂id', name: 'factoryId', index: 'factory_id', width: 80 }, 			
			{ label: '订单状态:active:活动订单,dead:已作废,finish:已完成,unactive:未激活,cancel:已取消', name: 'status', index: 'status', width: 80 }, 			
			{ label: '订单来源'pc','wap','weixin','ios','android','jd','taobao','suning','tmall','erp'', name: 'source', index: 'source', width: 80 }, 			
			{ label: '商品总值', name: 'totalAmount', index: 'total_amount', width: 80 }, 			
			{ label: '配送费用', name: 'costFreight', index: 'cost_freight', width: 80 }, 			
			{ label: '调价', name: 'discount', index: 'discount', width: 80 }, 			
			{ label: '商品促销优惠', name: 'pmtGoods', index: 'pmt_goods', width: 80 }, 			
			{ label: '优惠卷优惠', name: 'pmtOrder', index: 'pmt_order', width: 80 }, 			
			{ label: '随机立减', name: 'pmtRandom', index: 'pmt_random', width: 80 }, 			
			{ label: '订单应付金额', name: 'payableAmount', index: 'payable_amount', width: 80 }, 			
			{ label: '订单已支付金额', name: 'payed', index: 'payed', width: 80 }, 			
			{ label: '下单时间', name: 'orderCreateTime', index: 'order_create_time', width: 80 }, 			
			{ label: '收货时间', name: 'receivedTime', index: 'received_time', width: 80 }, 			
			{ label: '支付时间', name: 'paymentTime', index: 'payment_time', width: 80 }, 			
			{ label: '支付方式', name: 'payment', index: 'payment', width: 80 }, 			
			{ label: '是否分配 1是0 不是', name: 'isAllot', index: 'is_allot', width: 80 }, 			
			{ label: '打款状态0: 未打款 1：已打款', name: 'fundState', index: 'fund_state', width: 80 }, 			
			{ label: '打款时间', name: 'fundTime', index: 'fund_time', width: 80 }, 			
			{ label: '单据创建时间', name: 'createTime', index: 'create_time', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		merchantOrderAccount: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.merchantOrderAccount = {};
		},
		update: function (event) {
			var orderAccountId = getSelectedRow();
			if(orderAccountId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(orderAccountId)
		},
		saveOrUpdate: function (event) {
			var url = vm.merchantOrderAccount.orderAccountId == null ? "capital/merchantorderaccount/save" : "capital/merchantorderaccount/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.merchantOrderAccount),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var orderAccountIds = getSelectedRows();
			if(orderAccountIds == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "capital/merchantorderaccount/delete",
                    contentType: "application/json",
				    data: JSON.stringify(orderAccountIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(orderAccountId){
			$.get(baseURL + "capital/merchantorderaccount/info/"+orderAccountId, function(r){
                vm.merchantOrderAccount = r.merchantOrderAccount;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});